package com.heima.wemedia.config;

import com.heima.model.common.constants.message.PublishArticleConstants;
import org.springframework.amqp.core.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.management.Query;


/**
 * 所需的所有交换机
 * 队列 绑定关系
 */
@Configuration
public class DeclarePubArticleRabbitConfig {
    /**
     * 配置延迟交换机
     * @return
     */
    @Bean
    public DirectExchange delayExchange(){
        return ExchangeBuilder.directExchange(PublishArticleConstants.DELAY_DIRECT_EXCHANGE)
                .delayed() //延迟
                .durable(true) //是否持久化
                .build();
    }


    /**
     * 创建队列
     * @return
     */
    @Bean
    public Queue publishArticleQueue(){
        return new Queue(PublishArticleConstants.PUBLISH_ARTICLE_QUEUE,true);
    }

    /**
     * 完成绑定
     * @return
     */
    @Bean
    public Binding bindingPublishArticleQueue(){
        return BindingBuilder.bind(publishArticleQueue()).to(delayExchange()).with(PublishArticleConstants.PUBLISH_ARTICLE_ROUTE_KEY);
    }

}
